package com.y.fund.domain.mem;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.y.fund.aacore.abs.TimeObj;
import com.y.fund.aacore.enums.LoginState;

import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Index;
import jakarta.persistence.Table;
import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
@Entity
@Table(name="mb15_lgn_record", indexes ={@Index(name="idx_last_opt_time", columnList = "last_opt_time")})
@Schema(title = "用户登录记录")
public class MB15LoginRecord extends TimeObj {

	@Schema(title = "用户ID")
	@Column(name = "user_id", length=64, nullable = false, updatable = false)
	private String userId;

	@Schema(title = "用户编号")
	@Column(name = "user_code", length=64, updatable = false)
	private String userCode;

	@Schema(title = "用户名称")
	@Column(name = "user_name", length=128, updatable = false)
	private String userName;

	@Column(name="client_type", length=32, nullable=false, updatable = false)
	@Schema(title = "登录类型  app-android, app-ios, web-")
	private String clientType;

	@Schema(title = "用户登录时间")
	@Column(name = "login_time", length=25, updatable = false)
	private String loginTime;

	@Schema(title = "最后操作时间")
	@Column(name = "last_opt_time", length=25)
	private String lastOptTime;

	@Schema(title = "用户退出时间, yyyy-MM-dd HH:ss:mm")
	@Column(name = "logout_time", length=25)
	private String logoutTime;

	@Schema(title = "登录状态；1：登录中，-1：已退出，-2：被管理员强制退出；")
	@Column(name = "lgn_status")
	private Integer status;
	
	@JsonIgnore
	@Override
	public boolean getNeedOperRecord() {
		return false;
	}

	public MB15LoginRecord() {
		super();
	}

	public static MB15LoginRecord ForUpdt(String loginId) {
		MB15LoginRecord login = new MB15LoginRecord();
		login.setId(loginId);
		return login;
	}
	
	public static MB15LoginRecord Login(String loginId, String userId, String userCode, String userName, String loginTime, String clientType) {
		MB15LoginRecord login = new MB15LoginRecord();
		login.setId(loginId);
		login.setStatus(LoginState.Login.getVal());
		login.setUserId(userId);
		login.setUserCode(userCode);
		login.setUserName(userName);
		login.setLoginTime(loginTime);
		login.setLastOptTime(loginTime);
		login.setClientType(clientType);
		
		return login;
	}

}
